/**
* Copyright (c) 2013-2014, qtone Inc. All Rights Reserved.
*
* @author: tanghuaicheng
* Project Name: testuc
* $Id:   2017-01-11 10:54:07 $
*  拼接sql查询条件。
*/

package cn.tang.tframe.mybatis.criteria;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class BaseGeneratedCriteria implements Serializable {
	protected List<BaseCriterion> criteria;
	private static final long serialVersionUID = 1L;
	protected BaseGeneratedCriteria() {
		super();
		criteria = new ArrayList<>();
	}

	public boolean isValid() {
		return criteria.size() > 0;
	}

	public List<BaseCriterion> getAllCriteria() {
		return criteria;
	}

	public List<BaseCriterion> getCriteria() {
		return criteria;
	}

	protected void addCriterion(String condition) {
		if (condition == null) {
			throw new RuntimeException("Value for condition cannot be null");
		}
		criteria.add(new BaseCriterion(condition));
	}

	protected void addCriterion(String condition, Object value, String property) {
		if (value == null) {
			throw new RuntimeException("Value for " + property + " cannot be null");
		}
		criteria.add(new BaseCriterion(condition, value));
	}

	protected void addCriterion(String condition, Object value1, Object value2, String property) {
		if (value1 == null || value2 == null) {
			throw new RuntimeException("Between values for " + property + " cannot be null");
		}
		criteria.add(new BaseCriterion(condition, value1, value2));
	}
}